define(["swiper"],function(Swiper){
	function navManu(){
		$("#page_nav").mouseenter(function(){
			$("#nav_manu").animate({top: "36px"}, 300);
		});
		 
		$("#page_nav").mouseleave(function(){
			let timer = setTimeout(function(){
				$("#nav_manu").animate({top: "-118px"}, 300);
			}, 200);
			$("#nav_manu").mouseenter(function(){
				clearTimeout(timer);
			});
			$("#nav_manu").mouseleave(function(){
				$("#nav_manu").animate({top: "-118px"}, 300);
			});
		});  
	}
	function searchDefauContent(){
		$.ajax({
			type: "get",
			url: "index.json",
			success: function(resq){
				let defaukw = resq.defaukw[0].c;
				let hotwords = resq.hotwords;
				$("#search_box").attr({
					value: defaukw,
				});
				hotwords.forEach(function(item){
					let l = $("<li></li>");
					let a = $("<a></a>");
					a.text(item.c);
					a.attr({href: "#"});
					l.append(a);
					$("#searchRecom").append(l);
				})
				
			},
			error: function(){
				
			}
		})
	}
	/* 产品分类二级菜单填充 */
	function classifyManuContent(sequenceNumber){
		$.ajax({
			type: "get",
			url: "classify.json",
			success: function(resq){
				let levels = resq.levels;
				levels.forEach(function(item){
					if(sequenceNumber == item.id){
						let ac = item.ac;
						let sec = item.sec;
						let $div = $("<div></div>");
						if(ac){
							let $p = $("<p></P>");
							$p.addClass("clear");
							ac.forEach(function(acItem){
								let $a = $("<a></a>");
								$a.attr({"href": "#"});
								$a.text(acItem.t);
								$p.append($a);
							});
							$div.append($p);
						}
						sec.forEach(function(secItem){
							let $dl = $("<dl></dl>");
							$dl.addClass("clear");
							let $dt = $("<dt></dt>");
							$dt.text(secItem.sect.t);
							$dl.append($dt);
							let secc = secItem.secc;
							let $dd = $("<dd></dd>");
							secc.forEach(function(seccItem){
								let $a = $("<a></a>");
								$a.attr({"href": "#"});
								$a.text(seccItem.t);
								$dd.append($a);
							})
							$dl.append($dd);
							$div.append($dl);
						})
						let $classifyManu = $("#classify_manu");
						$classifyManu.append($div);
					}
				})
			},
		})
	}
	/* 选择按钮 */
	function classifyButton(){
		$("#classify_button").on("mouseenter", "li",function(){
			$("#classify_manu div").remove();
			classifyManuContent($(this).attr("index"));
			$("#classify_button li").css({"background": "#E6E4E2"});
			$(this).css({"background": "#ffffff"});
			$("#classify_manu").css({"display": "block"});
			let i = $(this).attr("index");
		})
		
		$("#classify_button").on("mouseleave",function(){
			let timer = setTimeout(function(){
				$("#classify_button li").css({"background": "rgba(255,255,255,0.4)"});
				$("#classify_manu").css({"display": "none"});
			}, 100);
			$("#classify_manu").mouseenter(function(){
				clearTimeout(timer);
			})
			$("#classify_manu").on("mouseleave","div", function(){
				$("#classify_button li").css({"background": "rgba(255,255,255,0.4)"});
				$("#classify_manu").css({"display": "none"});
			})
		})
	}
	/* notice填充动画 */
	function noticeContent(){
		$.ajax({
			type: "get",
			url: "index.json",
			success: function(resq){
				let notice = resq.notice.nrom;
				notice.forEach(function(item){
					let $li = $("<li></li>");
					let $a = $("<a></a>");
					$a.attr({href: "#"});
					$a.text(item.t);
					$li.append($a);
					$("#notice2 ul:lt(1)").append($li);
				})
			}
		})
	}
	function runLine(){
		$("#notice1 li:lt(2)").mouseenter(function(){
			if($(this).index() == 0){
				$("#notice2 ul:lt(1)").animate({opacity: 100}).siblings().animate({opacity:0});
				$("#runline").animate({left: 12},100);
			}else if($(this).index() == 1){
				$("#runline").animate({left: 96},100);
				$("#notice2 ul:gt(1)").animate({opacity: 100}).siblings().animate({opacity:0});
			}
		})
	}
	function hotzoneplateContent(selector){
		$.ajax({
			type: "get",
			url: "index.json",
			success: function(resq){
				let hotZone = resq.hotzone.catr1;
				let h = "";
				for(let i in hotZone){
					if(i != "index"){
						let t = proModule(hotZone[i]);
						h += t;
						$(selector).html(h);
					}
				}
				
			}
		})
	}
	function hotzoneplateContent1(selector){
		$.ajax({
			type: "get",
			url: "index.json",
			success: function(resq){
				let hotZone = resq.hotzone.catr2;
				let h = "";
				for(let i in hotZone){
					if(i != "index"){
						let t = proModule(hotZone[i]);
						h += t;
						$(selector).html(h);
					}
				}
				
			}
		})
	}
	
	function proModule(data){
		let ai = `<i>${data.mod[0].b}</i>`
		let t = `
			<div>
				<dl>
					<dt>${data.tit}</dt>
					<dd>
						<a href="">${data.tiw[0].t}</a><span>\\</span>
						<a href="">${data.tiw[1].t}</a><span>\\</span>
						<a href="">${data.tiw[2].t}</a>
					</dd>
				</dl>
				<a href="#">
					<img src=${data.mod[0].i} >
					<p>${data.mod[0].n}</p>
					<b>${data.mod[0].d}</b>
					<i>${data.mod[0].b}</i>
				</a>
				<a href="#">
					<img src=${data.mod[1].i} >
					<p>${data.mod[1].n}</p>
					<b>${data.mod[1].d}</b>
					<i>${data.mod[1].b}</i>
				</a>
			</div>
		`;
		return t;
	}
	function screenSlide(selector){
		$(selector).on("mouseenter","a",function(){
			$(this).stop().animate({width: 400}, 500).siblings().stop().animate({width: 156}, 300);
		})
		$(selector).mouseleave(function(){
			$(selector).children().animate({width: 196});
		})
	}
	function absorbTop(selector){
		var timer = null;
		$(window).scroll(function(){
			clearTimeout(timer);
			if($(document).scrollTop() > 500){
				timer = setTimeout(function() {
					$(selector).addClass("absorb-top");
				}, 100);
			}else{
				timer = setTimeout(function(){
					$(selector).removeClass("absorb-top");
				})
			}
		})
	}
	return {
		navManu,
		searchDefauContent,
		classifyButton,
		runLine,
		noticeContent,
		hotzoneplateContent,
		hotzoneplateContent1,
		screenSlide,
		absorbTop,
		
	}
})